<template>
    <view>
        <!-- search -->

        <view class="container_2">
            <view :class="(scrollTop > 85 && jobln > 7) || scrollTop == 146 ? 'header_2_fixed' : 'header_2'">
                <navigator url="../city/index?id=1" hover-class="none">
                    <view class="city_2">
                        <text class="fa fa-map-marker fa-lg"></text>
                        {{ city }}
                    </view>
                </navigator>
                <view class="search_2" @tap="toSelectJob">
                    <icon style="margin-top: 0;" type="search" size="14" />
                    <view>请搜索职位名称</view>
                </view>
            </view>

            <view :class="(scrollTop > 85 && jobln > 7) || scrollTop == 146 ? 'selectcars_fixed' : 'selectcars'">
                <view class="itemselectcars" @tap="toSelectArea" data-id="1">
                    {{ areatitle ? areatitle : '区域' }}
                    <image src="/static/imgs/icon/down.png"></image>
                </view>
                <view class="itemselectcars" style="width: 18%" @tap="toSelectType">
                    {{ typetitle ? typetitle : '类别' }}
                    <image src="/static/imgs/icon/down.png"></image>
                </view>

                <view class="itemselectcars" style="width: 18%" @tap="toSelectPrice">
                    {{ pricetitle ? pricetitle : '薪资' }}
                    <image src="/static/imgs/icon/down.png"></image>
                </view>
                <view class="itemselectcars" style="width: 18%" @tap="toSelectCate">
                    {{ catetitle ? catetitle : '行业' }}
                    <image src="/static/imgs/icon/down.png"></image>
                </view>

                <view class="itemselectcars" style="width: 20%" @tap="toSelectJob">
                    筛选
                    <image src="/static/imgs/icon/select2.png" style="width: 35rpx; height: 35rpx"></image>
                </view>

                <view class="select_cars" v-if="!isArea">
                    <view class="select_cars_list" @tap="SelectAreaItem" data-title="全部" data-id="0">
                        <text>全部</text>

                        <image v-if="areaid == 0" src="/static/imgs/icon/dui.png"></image>
                    </view>

                    <view class="select_cars_list" @tap="SelectAreaItem" :data-title="item.name" :data-id="item.id" v-for="(item, index) in arealist" :key="index">
                        <text>{{ item.name }}</text>

                        <image v-if="areaid == item.id" src="/static/imgs/icon/dui.png"></image>
                    </view>
                </view>
            </view>

            <view class="small_overlay" v-if="!isArea"></view>

            <view class="select_price" v-if="!isType">
                <view class="item" style="width: 180rpx" @tap="SelectTypeItem" data-title="全部" data-id="-1">全部</view>

                <view class="item" @tap="SelectTypeItem" :data-title="item.name" :data-id="item.id" v-for="(item, index) in worktypelist" :key="index">{{ item.name }}</view>
            </view>

            <view class="small_overlay" v-if="!isType"></view>

            <view class="select_price" v-if="!isPrice">
                <view class="item" style="width: 180rpx" @tap="SelectPriceItem" data-title="不限" data-id="-1">不限</view>

                <view class="item" @tap="SelectPriceItem" data-title="2500-3000元" data-id="0-3">2500-3000元</view>

                <view class="item" @tap="SelectPriceItem" data-title="3000-5000元" data-id="3-5">3000-5000元</view>

                <view class="item" @tap="SelectPriceItem" data-title="5000-8000元" data-id="5-10">5000-8000元</view>

                <view class="item" @tap="SelectPriceItem" data-title="8000-10000元" data-id="10-15">8000-10000元</view>
                <view class="item" @tap="SelectPriceItem" data-title="10000元以上" data-id="10-15">10000元以上</view>
            </view>

            <view class="small_overlay" v-if="!isPrice"></view>

            <view class="select_price" v-if="!isCate">
                <view class="item" style="width: 180rpx" @tap="SelectCateItem" data-title="不限" data-id="0">不限</view>

                <view class="item" @tap="SelectCateItem" :data-title="item.name" :data-id="item.id" v-for="(item, index) in jobcatelist" :key="index">{{ item.name }}</view>
            </view>

            <view class="small_overlay" v-if="!isCate"></view>

            <!-- 列表 -->
            <view class="news">
                <!-- parse <template is="nearjoblist" v-if="joblist" :data="joblist"/> -->
                <block name="nearjoblist" v-if="joblist">
                    <view class="joblist_2" v-for="(item, index) in joblist" :key="index">
                        <view class="title_2" @tap="toJobDetail" :data-id="item.id">
                            <view class="jobinfo_2">
                                <view class="jobinfoleft_2">
                                    <view class="address_2">
                                        <view class="jobname_2">{{ item.jobtitle }}</view>

                                        <view class="moneyinfo_2">
                                            <block v-if="item.money == 0">面议</block>
                                            <block v-else>{{ item.money }}</block>
                                        </view>
                                        <view class="vprice2"></view>
                                    </view>

                                    <view class="joblable_2">{{ item.areaname }} | {{ item.education }}</view>

                                    <view class="special_2">
                                        <view class="items_2" v-for="(itemSpecial, index1) in item.speciallist" :key="index1">{{ itemSpecial }}</view>

                                        <!--
                                                    <view class="items_2" >月休</view> 
                                                    <view class="items_2" >免费培训</view>
                                                    <view class="items_2" >晋升空间</view>
                                                    <view class="items_2" >综合补贴</view>
                                                       -->
                                    </view>
                                </view>

                                <view class="jobinforight_2">
                                    <view class="fxmoney_2" v-if="item.vprice > 0">
                                        <view style="width: 200rpx; color: #fff">推荐奖300元/人</view>
                                        <view>入职奖100元/人</view>
                                    </view>
                                </view>
                            </view>

                            <view class="detail_2">
                                <view class="info_2">
                                    <view class="companyinfo_2" style="font-size: 0.9rem">
                                        {{ item.companyname }}
                                    </view>
                                    <view class="jobmoney_2">
                                        <view class="time_2">{{ item.distance }}km</view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </block>
            </view>
        </view>

        <!-- 加载更多 -->
        <view class="loadmore">
            <text>{{ loadMore }}</text>
        </view>
    </view>
</template>

<script>
import { Findjob } from './findjob-model.js';
var findjob = new Findjob(); //实例化 首页 对象
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
var qqmapsdk;
export default {
    data() {
        return {
            city: uni.getStorageSync('companyinfo').city,
            isCars: true,

            // 选择车源开关
            isSort: true,

            // 选择排序开关
            isPrice: true,

            // 选择价格开关
            isType: true,

            loadMore: '',
            page: 1,
            isArea: true,
            areaid: 0,
            priceid: 0,
            cateid: 0,
            isPrice: true,
            isCate: true,
            areatitle: '',
            pricetitle: '',
            catetitle: '',
            typetitle: '',
            jobln: 0,
            typeid: 0,
            scrollTop: '',
            joblist: '',
            arealist: [],
            worktypelist: [],
            jobcatelist: []
        };
    },
    onPageScroll: function (t) {
        console.log(t.scrollTop); //会随着用户下滑页面值变大
        var that = this;
        if (t.scrollTop <= 145) {
            that.isArea = true;
            that.isPrice = true;
            that.isCate = true;
            that.setData({
                isArea: that.isArea,
                isPrice: that.isPrice,
                isCate: that.isCate
            });
        }
        that.setData({
            scrollTop: t.scrollTop
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onShow: function (options) {
        this.onShowClone3389(options);
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},
    /**
     * 生命周期函数--监听页面显示
     */

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {},
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {},
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        uni.showNavigationBarLoading();
        this.onShowClone3389({});
    },
    /**
     * 页面上拉触底事件的处理函数
     */

    onReachBottom(params) {
        var that = this;
        /*
  that.setData({
    loadMore: '正在加载中...'
  })
   */
        this.page = this.page + 1;
        this.getjoblist();
    },
    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
        return {
            title: '找工作',
            path: '/pages/findjob/index'
        };
    },
    methods: {
        /**
         * 生命周期函数--监听页面加载
         */
        onShowClone3389: function (options) {
            var that = this;
            uni.setNavigationBarTitle({
                title: '附近职位'
            });
            uni.showShareMenu({
                withShareTicket: true,
                menus: ['shareAppMessage', 'shareTimeline']
            });
            var cityinfo = uni.getStorageSync('cityinfo');
            console.log(cityinfo);
            if (cityinfo) {
                uni.setStorageSync('city', cityinfo.name);
                that.setData({
                    city: uni.getStorageSync('cityinfo').name
                });
            } else {
            }

            //获取信息
            qqmapsdk = new QQMapWX({
                // 必填
                key: '5D3BZ-J55WF-SFPJJ-NI6PG-YN2ZO-M4BHX'
            });

            uni.getLocation({
                type: 'gcj02',

                // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标
                success: function (res) {
                    uni.setStorageSync('latitude', res.latitude);
                    uni.setStorageSync('longitude', res.longitude);
                    qqmapsdk.reverseGeocoder({
                        location: {
                            latitude: res.latitude,
                            longitude: res.longitude
                        },

                        success: function (addressRes) {
                            that.getjoblist();
                        }
                    });
                },

                fail: function (res) {
                    // fail
                    console.log(res);
                    that._loadData();
                },

                complete: function () {}
            });
        },

        toSelectType: function () {
            var that = this;
            that.scrollTop = 146;
            that.isPrice = true;
            that.isType = false;
            that.isArea = true;
            that.isCate = true;
            that.setData({
                isType: that.isType,
                isPrice: that.isPrice,
                isArea: that.isArea,
                isCate: that.isCate,
                scrollTop: that.scrollTop
            });
        },

        toSelectPrice: function () {
            var that = this;
            that.scrollTop = 146;
            that.isPrice = false;
            that.isArea = true;
            that.isCate = true;
            that.isType = true;
            that.setData({
                isPrice: that.isPrice,
                isArea: that.isArea,
                isCate: that.isCate,
                isType: that.isType,
                scrollTop: that.scrollTop
            });
        },

        toSelectCate: function () {
            var that = this;
            that.scrollTop = 146;
            that.isCate = false;
            that.isPrice = true;
            that.isArea = true;
            that.isType = true;
            that.setData({
                isPrice: that.isPrice,
                isArea: that.isArea,
                isCate: that.isCate,
                isType: that.isType,
                scrollTop: that.scrollTop
            });
        },

        toSelectArea: function () {
            var that = this;
            that.scrollTop = 146;
            that.isArea = false;
            that.isCate = true;
            that.isPrice = true;
            that.isType = true;
            that.setData({
                isPrice: that.isPrice,
                isArea: that.isArea,
                isCate: that.isCate,
                isType: that.isType,
                scrollTop: that.scrollTop
            });
        },

        SelectAreaItem: function (e) {
            var that = this;
            that.scrollTop = 16;
            var areaid = e.currentTarget.dataset.id;
            that.areatitle = e.currentTarget.dataset.title;
            that.areaid = areaid;
            that.isArea = true;
            that.setData({
                areaid: that.areaid,
                isArea: that.isArea,
                areatitle: that.areatitle,
                scrollTop: that.scrollTop
            });
            that.getjoblist();
        },

        SelectPriceItem: function (e) {
            var that = this;
            that.scrollTop = 16;
            var priceid = e.currentTarget.dataset.id;
            that.pricetitle = e.currentTarget.dataset.title;
            that.priceid = priceid;
            that.isPrice = true;
            that.setData({
                priceid: that.priceid,
                isPrice: that.isPrice,
                pricetitle: that.pricetitle,
                scrollTop: that.scrollTop
            });
            that.getjoblist();
        },

        SelectCateItem: function (e) {
            var that = this;
            that.scrollTop = 16;
            var cateid = e.currentTarget.dataset.id;
            that.catetitle = e.currentTarget.dataset.title;
            that.cateid = cateid;
            that.isCate = true;
            that.setData({
                cateid: that.cateid,
                isCate: that.isCate,
                catetitle: that.catetitle,
                scrollTop: that.scrollTop
            });
            that.getjoblist();
        },

        SelectTypeItem: function (e) {
            var that = this;
            that.scrollTop = 16;
            var typeid = e.currentTarget.dataset.id;
            that.typetitle = e.currentTarget.dataset.title;
            that.typeid = typeid;
            that.isType = true;
            that.setData({
                typeid: that.typeid,
                isType: that.isType,
                typetitle: that.typetitle,
                scrollTop: that.scrollTop
            });
            that.getjoblist();
        },

        toSelectJob: function () {
            var that = this;
            uni.navigateTo({
                url: '/pages/selectjob/index'
            });
        },

        getjoblist: function () {
            var that = this;
            var cityid = uni.getStorageSync('cityinfo').id;
            var latitude = uni.getStorageSync('latitude');
            var longitude = uni.getStorageSync('longitude');
            var params = {
                cityid: cityid,
                page: that.page,
                areaid: that.areaid,
                priceid: that.priceid,
                jobcateid: that.cateid,
                latitude: latitude,
                longitude: longitude,
                type: that.typeid
            };
            findjob.getNearJobListData((data) => {
                console.log(data);
                that.setData({
                    joblist: data.joblist
                });
            }, params);
        },

        toJobDetail: function (e) {
            var id = e.currentTarget.dataset.id;
            uni.navigateTo({
                url: '/pages/jobdetail/index?id=' + id
            });
        }
    }
};
</script>
<style>
@import '../templates/css/index_2.css'; /* search */
/**app.wxss**/
page {
    background-size: 100% 100%;
    height: 100%;
    font-size: 32rpx;
    font-family: '微软雅黑', '方正黑体';
    color: #333;
}

.container_2 {
    background-color: #f0f1f5;
    min-height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/*
.search image {
	width: 30rpx;
	height: 34rpx;
	padding-right: 3px;
	vertical-align: sub;
}

.search text {
	line-height: 30px;
	font-size: 14px;
	color: #e62129;
}

.search_box {
	display: flex;
	flex: 1;
	height: 30px;
	padding-left: 15px;
	margin: 10px 0 0 10px;
	background-color: #f7f7f7;
}

.search_box icon {
	padding-top: 8px;
}

.search_box text {
	flex: 1;
	padding-left: 5px;
	color: #999;
}

*/

.header_2 {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    padding-top: 30rpx;
    padding-bottom: 30rpx;
    background: #fff;
}
.header_2_fixed {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: space-around;
    padding-top: 30rpx;
    padding-bottom: 30rpx;
    background: #fff;
    position: fixed;
    z-index: 100;
    top: 0px;
}

.city_2 {
    height: 80rpx;
    line-height: 80rpx;
    color: #000000;
    font-size: 0.9rem;
    font-weight: 600;
}
.search_2 {
    width: 500rpx;
    height: 80rpx;
    line-height: 80rpx;
    background: #f0f1f5;
    display: flex;
    flex-direction: row;
    justify-content: center;
    border-radius: 30rpx 30rpx 30rpx 0rpx;
}
.search_2 view {
    color: #a6a6a6;
    font-size: 0.7rem;
    align-self: center;
}
.search_2 icon {
    margin-right: 20rpx;
    margin-top: 18rpx;
}

.selectcars {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    padding: 20rpx;
    font-size: 0.8rem;
    background: #ffffff;
}
.selectcars_fixed {
    width: 100%;
    display: flex;
    flex-direction: row;
    justify-content: flex-start;
    padding: 20rpx;
    font-size: 0.8rem;

    z-index: 1112;
    position: fixed;
    top: 120rpx;
    background: #fff;
}

.itemselectcars {
    display: flex;
    flex-direction: row;
    height: 60rpx;
    justify-content: center;
    align-items: center;
    width: 24%;
}

.itemselectcars image {
    width: 15rpx;
    height: 15rpx;
    align-self: center;
    margin-left: 5rpx;
}

.red {
    color: #fd6a36;
}

.select_cars,
.select_sort,
.select_price {
    position: fixed;
    top: 97px;
    left: 0px;
    z-index: 888;
    width: 100%;
    padding-left: 30rpx;

    background-color: #fff;
}

.select_cars text,
.select_sort text {
    display: block;
    flex: 1;
    line-height: 35px;
    font-size: 13px;
}

.select_cars text:last-child,
.select_sort text:last-child {
    border-bottom: 0;
}

.select_cars_list {
    display: flex;
    border-bottom: 1px solid #ececec;
}

.select_cars_list image {
    width: 12px;
    height: 22px;
    padding-top: 8px;
    margin-right: 30rpx;
}
.select {
    border-bottom: 1px solid #e62129;
}

.select text {
    color: #e62129;
}

.select_price {
    display: flex;
    flex-direction: row;
    justify-content: center;
    flex-wrap: wrap;
    padding: 6px 4%;
    padding-top: 30rpx;
}
.select_price .item {
    height: 80rpx;
    background: #f3f3f3;
    padding-left: 15rpx;
    padding-right: 15rpx;
    border-radius: 35rpx;
    margin-right: 22rpx;
    margin-bottom: 20rpx;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 12px;
}

/* 遮罩层 */
.small_overlay {
    position: fixed;
    width: 100%;
    height: 80%;
    bottom: 0;
    left: 0;
    z-index: 666;
    background-color: rgba(0, 0, 0, 0.5);
}

.imglabel {
    position: absolute;
    top: -10rpx;
    left: -15rpx;
}

@import 'undefined';
</style>
